// support.cpp -- use external variable
// compile with external.cpp
//#include <iostream>
//extern double warming;	// use warming from another file
//
//// function prototypes
//void update(double dt);
//void local();
//
//using std::cout;
//void update(double dt)	// modifies global variable
//{
//	//extern double warming;	// optional redeclaration
//	warming += dt;			// uses global warming
//	cout << "Updating global warming to " << warming;
//	cout << " degress.\n";
//}
//
//void local()		// uses local variable
//{
//	double warming = 0.8;	// new variable hides external one
//
//	cout << "Local warming = " << warming << " degrees.\n";
//		// Access global variable with the scope resolution operator
//	cout << "But global warming = " << ::warming;
//	cout << " degrees.\n";
//}

// towfile2.cpp -- variables with internal and external linkage
//#include <iostream>
//extern int tom;			// tom defined elsewhere
//static int dick = 10;	// overrides external dick
//int harry = 200;		// external variable definition,
//						// no conflict with twofile1 harry
//
//void remote_access()
//{
//	using namespace std;
//	cout << "remote_access() reports the following addresses:\n";
//	cout << &tom << " = &tom, " << &dick << " = &dick, ";
//	cout << &harry << " = &harry\n";
//}

// usenmsp.cpp -- using namespaces
//#include <iostream>
//#include "test_240216.h"
//
//void other(void);
//void another(void);
//int main(void)
//{
//	using debts::Debt;
//
//	using debts::showDebt;
//	Debt golf = { {"Bennny", "Goatsniff"}, 120.0 };
//	showDebt(golf);
//	other();
//	another();
//
//	return 0;
//}
//
//void other(void)
//{
//	using std::cout;
//	using std::endl;
//	using namespace debts;
//	Person dg = { "Doodles", "Glister" };
//	showPerson(dg);
//	cout << endl;
//	Debt zippy[3];
//	int i;
//	for (i = 0; i < 3; i++)
//	{
//		getDebt(zippy[i]);
//	}
//
//	for (i = 0; i < 3; i++)
//	{
//		showDebt(zippy[i]);
//	}
//	cout << "Total debt: $" << sumDebts(zippy, 3) << endl;
//	return;
//}
//
//void another(void)
//{
//	using pers::Person;
//	Person collector = { "Milo", "Rightshift" };
//	pers::showPerson(collector);
//	std::cout << std::endl;
//}

// stock00.cpp -- implementing the Stock class
// version 00
//#include <iostream>
//#include "test_240216.h"
//
//void Stock::acquire(const std::string& co, long n, double pr)
//{
//	company = co;
//	if (n < 0)
//	{
//		std::cout << "Number of shares can't be negative; "
//			<< company << " shares set to 0.\n";
//		shares = 0;
//	}
//	else
//	{
//		shares = n;
//	}
//	share_val = pr;
//	set_tot();
//}
//
//void Stock::buy(long num, double price)
//{
//	if (num < 0)
//	{
//		std::cout << "Number of shares purchased can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares += num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::sell(long num, double price)
//{
//	using std::cout;
//	if (num < 0)
//	{
//		cout << "Number of shares sold can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else if (num > shares)
//	{
//		cout << "You can't sell more than you have! "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares -= num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::update(double price)
//{
//	share_val = price;
//	set_tot();
//}
//
//void Stock::show()
//{
//	using std::cout;
//	using std::ios_base;
//	// set format to #.###
//	ios_base::fmtflags orig =
//		cout.setf(ios_base::fixed, ios_base::floatfield);
//	std::streamsize prec = cout.precision(3);
//
//	cout << "Company: " << company
//		<< "  Shares: " << shares << '\n'
//		<< "  Share Price: $" << share_val;
//	// set format to #.##
//	cout.precision(2);
//	cout << "  Total Worth: $" << total_val << '\n';
//
//	// restore original format
//	cout.setf(orig, ios_base::floatfield);
//	cout.precision(prec);
//}
//
//// usestck().cpp -- the client program
//// compile with stock00.cpp
//int main()
//{
//	Stock fluffy_the_cat;
//	fluffy_the_cat.acquire("NanoSmart", 20, 12.50);
//	fluffy_the_cat.show();
//	fluffy_the_cat.buy(15, 18.125);
//	fluffy_the_cat.show();
//	fluffy_the_cat.sell(400, 20.00);
//	fluffy_the_cat.show();
//	fluffy_the_cat.buy(300000, 40.125);
//	fluffy_the_cat.show();
//	fluffy_the_cat.sell(300000, 0.125);
//	fluffy_the_cat.show();
//
//	return 0;
//}

// stock10.cpp -- Stock class with constructors, destructor added
//#include <iostream>
//#include "test_240216.h"
//
//// constructors (verbose versions)
//Stock::Stock()		// default constructor
//{
//	std::cout << "Default constructor called\n";
//	company = "no name";
//	shares = 0;
//	share_val = 0.0;
//	total_val = 0.0;
//}
//
//Stock::Stock(const std::string& co, long n, double pr)
//{
//	std::cout << "Constructor using " << co << " called\n";
//	company = co;
//
//	if (n < 0)
//	{
//		std::cout << "Number of shares can't be negative; "
//			<< company << " shares set to 0.\n";
//		shares = 0;
//	}
//	else
//	{
//		shares = n;
//	}
//	share_val = pr;
//	set_tot();
//}
//// class destructor
//Stock::~Stock()		// verbose class destructor
//{
//	std::cout << "Bye, " << company << "!\n";
//}
//
//// other methods
//void Stock::buy(long num, double price)
//{
//	if (num < 0)
//	{
//		std::cout << "Number of shares purchased can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares += num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::sell(long num, double price)
//{
//	using std::cout;
//	if (num < 0)
//	{
//		cout << "Number of shares sold can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else if (num > shares)
//	{
//		cout << "You can't sell more than you have! "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares -= num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::update(double price)
//{
//	share_val = price;
//	set_tot();
//}
//
//void Stock::show()
//{
//	using std::cout;
//	using std::ios_base;
//	// set format to #.###
//	ios_base::fmtflags orig =
//		cout.setf(ios_base::fixed, ios_base::floatfield);
//	std::streamsize prec = cout.precision(3);
//
//	cout << "Company: " << company
//		<< "  Shares: " << shares << '\n'
//		<< "  Share Price: $" << share_val;
//	// set format to #.##
//	cout.precision(2);
//	cout << "  Total Worth: $" << total_val << '\n';
//
//	// restore original format
//	cout.setf(orig, ios_base::floatfield);
//	cout.precision(prec);
//}
//
//// usestock1.cpp -- using the Stock class
//// compile with stock10.cpp
//
//int main()
//{
//	{
//		using std::cout;
//		cout << "Using constructors to create new objects\n";
//		Stock stock1("NanoSmart", 12, 20.0);			// syntax 1
//		stock1.show();
//		Stock stock2 = Stock("Boffo Objects", 2, 2.0);	// syntax 2
//		stock2.show();
//
//		cout << "Assigning stock1 to stock2:\n";
//		stock2 = stock1;
//		cout << "Listing stock1 and stock2:\n";
//		stock1.show();
//		stock2.show();
//
//		cout << "Using a constructor to reset an object\n";
//		stock1 = Stock("Nifty Foods", 10, 50.0);		// temp object
//		cout << "Revised stock1:\n";
//
//		stock1.show();
//		cout << "Done\n";
//	}
//
//	return 0;
//}

// stock20.cpp -- augmented version
//#include <iostream>
//#include "test_240216.h"
//
//// constructors
//Stock::Stock()		// default constructor
//{
//	company = "no name";
//	shares = 0;
//	share_val = 0.0;
//	total_val = 0.0;
//}
//
//Stock::Stock(const std::string& co, long n, double pr)
//{
//	company = co;
//
//	if (n < 0)
//	{
//		std::cout << "Number of shares can't be negative; "
//			<< company << " shares set to 0.\n";
//		shares = 0;
//	}
//	else
//	{
//		shares = n;
//	}
//	share_val = pr;
//	set_tot();
//}
//
//// class destructor
//Stock::~Stock()		// quiet class destructor
//{}
//
//// other methods
//void Stock::buy(long num, double price)
//{
//	if (num < 0)
//	{
//		std::cout << "Number of shares purchased can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares += num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::sell(long num, double price)
//{
//	using std::cout;
//	if (num < 0)
//	{
//		cout << "Number of shares sold can't be negative. "
//			<< "Transaction is aborted.\n";
//	}
//	else if (num > shares)
//	{
//		cout << "You can't sell more than you have! "
//			<< "Transaction is aborted.\n";
//	}
//	else
//	{
//		shares -= num;
//		share_val = price;
//		set_tot();
//	}
//}
//
//void Stock::update(double price)
//{
//	share_val = price;
//	set_tot();
//}
//
//void Stock::show() const
//{
//	using std::cout;
//	using std::ios_base;
//	// set format to #.###
//	ios_base::fmtflags orig =
//		cout.setf(ios_base::fixed, ios_base::floatfield);
//	std::streamsize prec = cout.precision(3);
//
//	cout << "Company: " << company
//		<< "  Shares: " << shares << '\n'
//		<< "  Share Price: $" << share_val;
//	// set format to #.##
//	cout.precision(2);
//	cout << "  Total Worth: $" << total_val << '\n';
//
//	// restore original format
//	cout.setf(orig, ios_base::floatfield);
//	cout.precision(prec);
//}
//
//const Stock& Stock::topval(const Stock& s) const
//{
//	if (s.total_val > total_val)
//	{
//		return s;
//	}
//	else
//	{
//		return *this;
//	}
//}
//
//// usestok2.cpp -- using the Stock class
//// compile with stock20.cpp
//
//const int STKS = 4;
//int main()
//{
//	// create an array of initialized objects
//	Stock stocks[STKS] = {
//		Stock("NanoSmart", 12, 20.0),
//		Stock("Boffo Objects", 200, 2.0),
//		Stock("Monolithic Obelisks", 130, 3.25),
//		Stock("Fleep Enterprises", 60, 6.5)
//	};
//
//	std::cout << "Stock holdings:\n";
//	int st;
//	for (st = 0; st < STKS; st++)
//	{
//		stocks[st].show();
//	}
//
//	// set pointer to first element
//	const Stock* top = &stocks[0];
//	for (st = 1; st < STKS; st++)
//	{
//		top = &top->topval(stocks[st]);
//	}
//
//	// now top points to the most valuable holding
//	std::cout << "\nMost valuable holding:\n";
//	top->show();
//
//	return 0;
//}